// 获取全局 app 实例
const app = getApp();
Page({
  data: {

    fundName: null,
    fundCode: null,
    fundAmt: null,
    opdnid: null


  },
  onSubmit(e) {


    this.saveFundInfo(e);


  },
  onReset() {

  },
  handleInputChange: function (e) {
    console.log("e", e);
  },

  async saveFundInfo(e) {
    const c1 = my.cloud.createCloudContext({
      env: 'env-00jxgeypg2iy', // 云环境 id
    });
    await c1.init();

    var json = e.detail.value;

    let ropenides = my.getStorageSync({
      key: 'openid'
    });
    json["openId"] = ropenides.data;
    my.showLoading({
      content: '保存中...',
      success: function (res) {
        console.log(res);
        setTimeout(() => {
          my.hideLoading();

        }, 1500);
      },
      fail: function (err) {
        console.log(err);
      }
    });



    console.log("e.detail.value", json);
    var context = app.context;
    await context.init()
    const res = context.callContainer({
      path: '/database/saveFindInfo',
      method: 'POST',
      data: json,
      header: {
        "X-Alipay-Service": "yongserver", //换成你自己的环境内的服务名
        "Content-Type": "application/json" // 不加这一行，其实就不需要服务端返回的数据限制为json了。啥都不加，其实默认就是 text，如果加了 json，jsapi就可以帮助反序列化json，
      }
    }).then((res) => {



      console.log("getList then respose", res.resultData.data)

      c1.callFunction({
        name: "addFundInfo",
        data: {
          action: "addFundInfo",
          fundName: res.resultData.data.fundInfoList[0].fundName,
          fundAmt: res.resultData.data.fundInfoList[0].fundAmt,
          fundCode: res.resultData.data.fundInfoList[0].fundCode,
          importDate: res.resultData.data.fundInfoList[0].fixDate,
          fundCount: res.resultData.data.fundInfoList[0].fundCount,
          todayAmt: res.resultData.data.fundInfoList[0].todayAmt,
          openId: ropenides.data



        }
      });

      my.reLaunch({
        url: "../index/index" // url详解请见【路由使用须知】
      })
    })
  },

});